"""
    @Author  ：思念 
    @File    ：4.线程方法-线程信息.py
    @Date    ：2025/1/8 11:43 
"""

import threading
import time


def work():
    name = threading.current_thread().getName()
    print(name)
    time.sleep(3)


for i in range(5):
    t = threading.Thread(target=work)
    t.start()

# 获取所有活动线程的信息
threads = threading.enumerate()

print("-------------")

# 打印线程信息
for thread in threads:
    print(f"线程名称: {thread.name}")
    print(f"线程ID: {thread.ident}")
    print(f"是否存活: {thread.is_alive()}")
    print("-" * 20)
